<!DOCTYPE html >
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>修改文章</title>
    <link rel="stylesheet" href="/static/home/bootstrap/css/bootstrap.min.css">
</head>

<body>
<div class='container' style="margin-bottom: 50px;margin-top: 20px">
    <div class='col-md-8'>
        <form id="user_form" action="/blog/paper/updatepaper" role="form">
            <div class="form-group">
                <div class="alert alert-warning" id='warning-block'>
                    <p>修改文章</p>
                </div>
                <div>
                    <label>标题</label>
                    <input type="text" class="form-control" name="title" id="title"
                           placeholder="请输入标题" required="required" value="{{.thispaper.Title}}">
                </div>
                <div id="titleTip"></div>
                <div>
                    <label>作者</label>
                    <input type="text" class="form-control" name="author" id="author"
                           placeholder="请输入作者" required="required" value="{{.thispaper.Author}}">
                </div>
                <div id="authorTip"></div>
                <div>
                    <label>目录：</label>
                    <select name='cid' id='cid' class="form-control">
                    {{range $index, $e :=.category}}
                        {{if eq $e.Id $.thispaper.Cid}}
                        <option value="{{$e.Id}}" selected="selected">{{$e.Title}}</option>
                        {{else}}
                        <option value="{{$e.Id}}">{{$e.Title}}</option>
                        {{end}}
                    {{range $index1, $e1 :=$e.Son}}
                        {{if eq $e1.Id $.thispaper.Cid}}
                        <option value="{{$e1.Id}}" selected="selected">-------{{$e1.Title}}</option>
                        {{else}}
                        <option value="{{$e1.Id}}">-------{{$e1.Title}}</option>
                        {{end}}
                    {{end}}
                    {{end}}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label>简介</label>
                <textarea id="editor1" class="form-control" rows="5" name="descontent" placeholder="简介">{{.thispaper.Descontent}}</textarea>
            </div>
            <div class="form-group">
                <label>正文</label>
                <textarea id="editor" class="form-control"  name="content" rows="10" placeholder="正文">{{.thispaper.Content}}</textarea>
            </div>
            <div class="form-group">
                <label>文章排序</label>
                <input type="number" class="form-control" name="order" value={{.thispaper.Sort}} min="0"/>
            </div>

            <div class="form-group">
                <label>浏览量</label>
                <input type="number" class="form-control" name="view" value={{.thispaper.View}} min="0"/>
            </div>
            <div class="form-group">
                <label>文章状态</label>
                {{if eq .thispaper.Status 1}}
                <div class="radio">
                    <label>
                        <input type="radio" name="status" value="0">禁用文章
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="status" value="1"  checked>启用文章
                    </label>
                </div>
                {{else}}
                <div class="radio">
                    <label>
                        <input type="radio" name="status" value="0"  checked>禁用文章
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="status" value="1">启用文章
                    </label>
                </div>
                {{end}}
           </div>
            <div class="form-group">
                <label>置顶</label>
                {{if eq .thispaper.Istop 1}}
                <div class="radio">
                    <label>
                        <input type="radio" name="top" value="0">不置顶文章
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="top" value="1" checked>置顶文章
                    </label>
                </div>
                {{else}}
                <div class="radio">
                    <label>
                        <input type="radio" name="top" value="0" checked>不置顶文章
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="top" value="1">置顶文章
                    </label>
                </div>
                {{end}}
            </div>
            <div class="form-group">
                <label>是否设置轮转图</label>
                {{if eq .thispaper.Isroll 1}}
                <div class="radio">
                    <label>
                        <input type="radio" name="roll" value="0">不设置
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="roll" value="1" checked>设置
                    </label>
                </div>
                {{else}}
                <div class="radio">
                    <label>
                        <input type="radio" name="roll" value="0"  checked>不设置
                    </label>
                </div>
                <div class="radio">
                    <label>
                        <input type="radio" name="roll" value="1">设置
                    </label>
                </div>
                {{end}}
            </div>
            <div class="form-group">
                <label>自定义轮转地址</label>
                <input type="text" class="form-control" name="rollpath" value="{{.thispaper.Rollpath}}" />
            </div>
            <div id='uploadlogo'></div>
            <input type='text' name='id' value="{{.thispaper.Id}}" hidden="hidden">
            <div class="form-group">
                <div>
                    <button type="submit" class="btn btn-default">修改文章</button>
                </div>
            </div>

        </form>
    </div>
    <div class='col-md-3 col-md-offset-1'>
        <div align="center">
            <h1>图片</h1>

            <div>
                <img src="{{.thispaper.Photo}}" id='logoimg' class="am-img-responsive"
                     alt="图片"
                     style="border:1px red solid;height: 260px; width: 260px;"/>

                <p>请上传格式为.png .jpg .jpeg的图片。</p>

                <p>上传完毕后需要点击左边曾加按钮才能生效。</p>
            </div>
            <div id='uploadphotoconfirm' style='color:red'></div>
            <div>
                <button type="submit" class="btn btn-default" id='upload_button'>上传图片</button>
            </div>
            <div class="btn btn-success"><a id='lookphoto' href="{{.thispaper.Photo}}"
                                            target="_blank">查看图片</a></div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/static//admin/formvalidator4.1.3/jquery-1.7.2.min.js"></script>
<script src="/static/admin/formvalidator4.1.3/formValidator-4.1.3.min.js" type="text/javascript"
        charset="UTF-8"></script>
<script src="/static/admin/formvalidator4.1.3/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<link rel="stylesheet" href="/static/admin/kindeditor/themes/default/default.css"/>
<link rel="stylesheet" href="/static/admin/kindeditor/themes/simple/simple.css"/>
<script charset="utf-8" src="/static/admin/kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="/static/admin/kindeditor/lang/zh-CN.js"></script>
<script src="/static/tool/ajaxupload.js"></script>
<script type="text/javascript">
    KindEditor.ready(function (K) {
        var option = {
            themeType: 'simple',
            cssPath: '/static/admin/kindeditor/plugins/code/prettify.css',
            uploadJson: '/public/file/upload',
            fileManagerJson: '/public/file/filemanage',
            allowFileManager: true
        };
        var editor = K.create('textarea[name="content"]', option);
//        var editor1 = K.create('textarea[name="descontent"]', option);
        editor.sync();
//        editor1.sync();

        $.formValidator.initConfig({
            formID: "user_form", submitOnce: true,
            onSuccess: function () {
                var registerForm = $("#user_form");
                $.post(registerForm.attr("action"), registerForm.serialize(), function (data) {
                    alert(data.info);
                    $('#warning-block p').html('<strong>警告！</strong>' + data.info);
                    return;
                });
            }
        });

        $("#title").formValidator({onShowText: "请输入文章标题"})
                .inputValidator({
                    min: 1,
                    max: 100,
                    onError: "最多100个字符",
                    empty: {leftEmpty: false, rightEmpty: false, emptyError: "两边不能为空"}
                });
        $("#author").formValidator({onShowText: "请输入作者信息"})
                .inputValidator({
                    min: 1,
                    max: 100,
                    onError: "最多100个字符",
                    empty: {leftEmpty: false, rightEmpty: false, emptyError: "两边不能为空"}
                })
    });

</script>
<script>
    $(function () {
        var button = $('#upload_button'), interval;
        var confirmdiv = $('#uploadphotoconfirm');
        var fileType = "ptic", fileNum = "one";
        new AjaxUpload(button, {
            action: "/public/file/upload?dir=image",
            name: 'imgFile',
            responseType: 'json',
            onSubmit: function (file, ext) {
                if (fileType == "pic") {
                    if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)) {
                        this.setData({
                            'info': '文件类型为图片'
                        });
                    } else {
                        confirmdiv.text('文件格式错误，请上传格式为.png .jpg .jpeg 的图片');
                        return false;
                    }
                }

                confirmdiv.text('文件上传中');

                if (fileNum == 'one')
                    this.disable();

                interval = window.setInterval(function () {
                    var text = confirmdiv.text();
                    if (text.length <= 5) {
                        confirmdiv.text('文件上传中...');
                    } else {
                        confirmdiv.text('文件上传中');
                    }
                }, 200);
            },
            onComplete: function (file, response) {
                if (response.error == 1) {
                    confirmdiv.text(response.message);
                } else {
                    confirmdiv.text("上传完成");
                    $("#logoimg").attr("src", response.url);
                    $('#lookphoto').attr("href", response.url);
                    $("#uploadlogo").html("<input hidden='hidden' type='hidden'  name='photo' value='" + response.url + "'>");
                }

                window.clearInterval(interval);
                this.enable();
            }
        });
    });

</script>
</body>
</html>